package org.web2024.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.web2024.dao.*;
import org.web2024.service.TeacherService;
import org.web2024.service.serviceimp.AdminService;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;
    @PostMapping("/selectTeacherCourse")
    public Result selectTeacherCourse(@RequestBody OptionalCourse optionalcourse){
        String tno=((UserdetailsImp) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUser().getUser_no();
        String selCyear= optionalcourse.getSelCyear();
        System.out.println("selCyear: " + selCyear);
        List<Course> courseList = teacherService.selectTeacherCourse(tno, selCyear);
        if (courseList.isEmpty()) {
            return Result.fail("暂无课程");
        }
        return Result.success(courseList);
    }

    @PostMapping("/showTeacherInfo")
    public Result showTeacherInfo(){
        Teachar teacher = teacherService.showTeacherInfo();
        return Result.success(teacher);
    }
@PostMapping("/modifyTeacherInfo")
    public Result modifyTeacherInfo(@RequestBody Teachar teacher){
        boolean result = teacherService.modifyTeacherInfo(teacher);
        if (result) {
            return Result.success("修改成功");
        }
        return Result.fail("修改失败");
    }
}
